import 'package:flutter/cupertino.dart';
import 'package:badges/badges.dart';
import 'package:flutter/material.dart';

/**
 * 效果：小红点消息数
 * 插件：badges
 * 作用：在原来的基础上做调整、包括不同位数不同形状和大小
 */
class BradgeView extends StatelessWidget {
  late int mRedNum;
  late Widget child;

  BradgeView({
    Key? key,
    required this.mRedNum,
    required this.child,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Badge(
        shape: mRedNum < 10 ? BadgeShape.circle : BadgeShape.square,
        borderRadius: BorderRadius.circular(15),
        position: BadgePosition.topEnd(top: -10, end: -7),
        // padding: EdgeInsets.all(5),
        padding: mRedNum < 10 ? EdgeInsets.all(6) : EdgeInsets.all(3),
        //小红点内内容
        badgeContent: mRedNum < 10
            ? Text(
                '${mRedNum}',
                style: TextStyle(fontSize: 17, color: Colors.white),
              )
            : Text(
                '${mRedNum}',
                style: TextStyle(fontSize: 14, color: Colors.white),
              ),
        //小红点颜色
        badgeColor: mRedNum != 0 ? Colors.red : Colors.transparent,
        elevation: 0,
        //true时刷新时会在右则摆动一下
        showBadge: true,
        child: child);
  }

//数值>100 时候显示99+

}
